package com.zzyweb.rentalcarsys.controller;

import com.zzyweb.rentalcarsys.entity.Role;
import com.zzyweb.rentalcarsys.service.RoleService;
import com.zzyweb.rentalcarsys.utils.ResponseObject;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhiyi
 * @date 10/9/25
 **/
@RestController
@RequestMapping("/role")
@CrossOrigin
public class RoleController {
    @Autowired
    RoleService roleService;
    @GetMapping("/all")
    public ResponseObject getAllRoles() {
        List<Role> all = roleService.getAll();
        return ResponseObject.ok(all);
    }
    @PostMapping("/add")
    public ResponseObject addRole(@RequestBody Role role) {
        roleService.addRole(role);
        return ResponseObject.ok();
    }
    @PutMapping("/modify")
    public ResponseObject modifyRole(@RequestBody Role role) {
        roleService.modifyRole(role);
        return ResponseObject.ok();
    }

    @DeleteMapping("/delete/{roleId}")
    public ResponseObject deleteRole(@PathVariable Integer roleId) {
        roleService.deleteRole(roleId);
        return ResponseObject.ok();
    }

    @PostMapping("/modifyMenu/{ids}/{roleId}")
    public ResponseObject modifyMenuOfRole(@PathVariable(required = false) String ids, @PathVariable Integer roleId) {
        roleService.modifyMenuOfRole(ids,roleId);
        return ResponseObject.ok();
    }
}
